import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hao/utils/ColorUtil.dart';

typedef TypeSubmitBlock = void Function(String name);

class TypeDialog extends StatefulWidget {
  final TypeSubmitBlock typeSubmitBlock;

  TypeDialog({required this.typeSubmitBlock});

  @override
  _TypeDialogState createState() => _TypeDialogState();
}

class _TypeDialogState extends State<TypeDialog> {
  final titles = ["游戏号", "手机号", "车牌号"];
  final icons = const [
    Icon(Icons.gamepad_outlined),
    Icon(Icons.phone_android_outlined),
    Icon(Icons.car_repair)
  ];

  @override
  Widget build(BuildContext context) {
    return Material(
      color: Colors.transparent,
      child: Container(
        color: COLOR_WHITE_1.withOpacity(0.8),
        child: Center(
          child: Container(
            height: 300,
            width: Get.width * 0.8,
            decoration: BoxDecoration(
                color: COLOR_WHITE, borderRadius: BorderRadius.circular(10)),
            child: Column(
              children: [
                const SizedBox(
                  height: 15,
                ),
                const Text(
                  "请选择类别",
                  style: TextStyle(
                      fontWeight: FontWeight.bold,
                      fontSize: 20),
                ),
                const SizedBox(
                  height: 15,
                ),
                Column(
                  children: [
                    for (int i = 0; i < titles.length; i++)
                      GestureDetector(
                        onTap: () {
                          Get.back();
                          widget.typeSubmitBlock(titles[i]);
                        },
                        child: ListTile(
                          title: Text(titles[i]),
                          leading: icons[i],
                        ),
                      )
                  ],
                ),
                const SizedBox(
                  height: 10,
                ),
                GestureDetector(
                  onTap: () {
                    Get.back();
                  },
                  child: Container(
                    alignment: Alignment.center,
                    child: const Text(
                      "取消",
                      style: TextStyle(
                          color: Colors.white, fontWeight: FontWeight.w700),
                    ),
                    width: 100,
                    height: 40,
                    decoration: BoxDecoration(
                        color: MAIN_COLOR,
                        borderRadius: BorderRadius.circular(20)),
                  ),
                ),
                const SizedBox(
                  height: 15,
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}

void showTypeDialog(BuildContext context,
    {required TypeSubmitBlock typeSubmitBlock}) {
  showDialog(
      useSafeArea: false,
      context: context,
      builder: (BuildContext context) {
        return TypeDialog(typeSubmitBlock: typeSubmitBlock);
      });
}
